/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React from 'react';
import { message } from 'antd';
import type { ActionType } from '@ant-design/pro-table';
import { ShopListItems } from '../../../index.d';
import ProForm, { ModalForm, ProFormText, ProFormRadio } from '@ant-design/pro-form';
import { addAccount } from '@/services/jdk/register';

// hasShopId 无店铺无需传shop_id
interface RefuseModalProps {
  children: JSX.Element;
  tableRef: ActionType | any;
  item?: ShopListItems | any;
  hasShopId?: boolean;
}

const RefuseModal: React.FC<RefuseModalProps> = ({ item, children, tableRef, hasShopId }) => {
  const { user_id = '', city = '', id: shop_id = '' } = item || {};
  return (
    <ModalForm
      title={hasShopId ? '温馨提示' : '绑定运力并创建店铺'}
      trigger={children}
      width={500}
      modalProps={{
        destroyOnClose: true,
      }}
      onFinish={async (values) => {
        const { code, msg } = await addAccount({
          user_id,
          city,
          shop_id: hasShopId ? shop_id : '',
          ...values,
        });
        if (code == 0) {
          message.success('操作成功');
          tableRef.current?.reload();
          return true;
        } else {
          message.error(msg);
          return false;
        }
      }}
    >
      <ProFormRadio.Group
        name='delivery_brand'
        initialValue='sftc'
        options={[{ label: '顺丰同城', value: 'sftc' }]}
      ></ProFormRadio.Group>
      <ProForm.Group>
        <ProFormText
          width='xl'
          name='open_id'
          placeholder='请输入店铺ID'
          allowClear
          rules={[{ required: true, message: '请输入店铺ID' }]}
        />
      </ProForm.Group>
      <ProFormText
        width='xl'
        readonly
        fieldProps={{
          value:
            '温馨提示：让用户前往顺丰同城app —— 开发者工具进行授权聚单客开发者，APP ID为：1632067121',
        }}
      />
    </ModalForm>
  );
};

export default RefuseModal;
